﻿/// <reference path="Point.js" />
/// <reference path="Size.js" />



if (typeof (Element) != "undefined")
{
	Element.prototype.get_Location = function get_Location()
	{
		var x = 0;
		var y = 0;
		if (this.getBoundingClientRect)
		{
			var orect = this.getBoundingClientRect();
			x = orect.left;
			y = orect.top;
			var sp = window.get_ScrollPosition();
			x += sp.x;
			y += sp.y;
		}
		else
		{
			var t = this;
			while (t != null && t != document.body)
			{
				x += t.offsetLeft;
				y += t.offsetTop;
				t = t.offsetParent;
			}
		}
		return { x: x, y: y };
	}

	Element.prototype.get_OffsetLocation = function get_OffsetLocation()
	{
		var res = new Point(this.offsetLeft, this.offsetTop);

		var cur = this;
		while (cur.offsetParent.GetComputedStyle().position != "relative" && cur.offsetParent.GetComputedStyle().position != "absolute" && cur.offsetParent != document.body)
		{
			cur = cur.offsetParent;
			res.x += cur.offsetLeft;
			res.y += cur.offsetTop;
		}

		return res;
	}

	Element.prototype.get_OffsetParent = function get_OffsetParent()
	{
		var cur = this;
		while (cur.offsetParent.GetComputedStyle().position != "relative" && cur.offsetParent.GetComputedStyle().position != "absolute" && cur.offsetParent != document.body)
		{
			cur = cur.offsetParent;
		}

		return cur.offsetParent;
	}
}








window.get_Size = function get_Size()
{
	if (typeof (window.innerWidth) == 'number')
	{
		return new Size(window.innerWidth, window.innerHeight);
	}
	else if (document.documentElement != null && document.documentElement.clientWidth != null)
	{
		return new Size(document.documentElement.clientWidth, document.documentElement.clientHeight);
	}
	else if (document.body && document.body.clientWidth)
	{
		return new Size(document.body.clientWidth, document.body.clientHeight);
	}
	else
	{
		return new Size(0, 0);
	}
}
window.get_ScrollPosition = function get_ScrollPosition()
{
	var x = 0, y = 0;
	if (typeof (window.pageYOffset) == 'number')
	{
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	return new Point(x, y);
}
